fix: resolve balance aggregation issue for large token decimals - #9653
Merged
Conversation
removes old behaviour that was kept prior to WS issues around data in incorrect format, but now has been fixed
Prithpal-Sooriya
temporarily deployed
to
default-branch
July 24, 2026 14:47 — with
GitHub Actions
Inactive
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Prithpal-Sooriya
enabled auto-merge
July 27, 2026 15:51
Contributor
Author
|
@cursor get latest and fix merge conflicts ty |
|
Merged latest Conflict resolved
Post-merge fix
|
Resolve CHANGELOG conflict by keeping both unreleased entries. Fix tracing test to use arrangeAssetsControllerState helper. Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
juanmigdr
approved these changes
Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Explanation
Removes old behaviour that was kept prior from WS issues around data in incorrect format, but now has been fixed.
Also did some test spec cleaning...
References
MetaMask/metamask-extension#44786
Checklist
Example Extension Test:
Note
Medium Risk
Changes core balance aggregation math used for wallet/group fiat totals; the fix aligns with the invariant that state amounts are human-readable, but any edge case that still stored raw base units would now be mispriced.
Overview
Fixes incorrect portfolio totals when token balances are large human-readable amounts (e.g. billions of tokens with 9 decimals) by removing the legacy
scaleToHumanIfRawpath inbalance.tsaggregation.assetsBalanceamounts are always human-readable, but the old heuristic treated values ≥10^decimalsas raw base units and divided by10^decimals, which under-counted those holdings ingetAggregatedBalanceForAccount,getAggregatedBalanceForAccountIds,calculateBalanceForAllWallets, andcalculateBalanceChangeForAccountGroup(metamask-extension#44786).Tests add a TangYuan regression case, shared
arrangeAssetsControllerStatehelpers, and coverage for group aggregation when onlyaccountTreeStateis passed (noaccountsById). Changelog documents the fix.Reviewed by Cursor Bugbot for commit 7056a0b. Bugbot is set up for automated code reviews on this repo. Configure here.